package com.yexiao.cofe.business.controller;

import com.alibaba.fastjson2.JSONObject;
import com.yexiao.cofe.business.service.PermissionService;
import com.yexiao.cofe.resolver.IRequestToken;
import com.yexiao.core.response.ResponseData;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author lkl
 * @since 2025/4/9
 */
@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Resource
    private PermissionService permissionService;

    @PostMapping("/add")
    public ResponseData add(@RequestBody JSONObject param, @IRequestToken String token) {
        permissionService.addPermission(param, token);
        return ResponseData.success();
    }

    @GetMapping("/listAll")
    public ResponseData tree(@IRequestToken String token) {
        return ResponseData.success(permissionService.listAll(token));
    }

    @GetMapping("/del")
    public ResponseData delPermission(@RequestParam("permissionId") String permissionId, @IRequestToken String token) {
        permissionService.deletePermission(permissionId, token);
        return ResponseData.success();
    }

    @PostMapping("/update")
    public ResponseData updatePermission(@RequestBody JSONObject param, @IRequestToken String token) {
        permissionService.updatePermission(param, token);
        return ResponseData.success();
    }


}
